<template>
  <el-container class="homeContainer">
    <el-header>
      <span class="name">
        <i class="el-icon-s-grid"></i>电商后台管理系统
      </span>
      <el-button type="info" @click="loginOut" class="out">退出</el-button>
    </el-header>
    <el-container>
      <el-aside :width="isCollapse?'64px':'200px'">
        <div class="toggle-button" @click="toggle">
          <li class="el-icon-back"></li>
        </div>
        <el-menu
          :unique-opened="true"
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409eff"
          :default-active="activeIndex"
          :collapse="isCollapse"
          :collapse-transition="false"
          :router="true"
        >
          <el-submenu v-for="item in menuList" :key="item.id" :index="item.id+''">
            <template slot="title">
              <i :class="menuListIcon[item.id]"></i>
              <span>{{item.name}}</span>
            </template>
            <el-menu-item
              class="el-menu"
              v-for=" (child,index) in item.childList"
              :index="'/'+item.id+'-'+index"
              :key="index"
              @click="saveNavstate('/'+item.id+'-'+index)"
            >
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{child}}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-container>
        <el-main class="body">
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </el-container>
</template>
<script>
export default {
  created() {
    this.getMenuList();
    this.activeIndex=window.sessionStorage.getItem('activeIndex');
  },

  data() {
    return {
      isCollapse: false,
      menuList: [],
      menuListIcon: [
        "el-icon-user-solid",
        "el-icon-s-opportunity",
        "el-icon-s-cooperation",
        "el-icon-menu",
        "el-icon-notebook-1"
      ],
      activeIndex:""
    };
  },
  methods: {
    loginOut() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    getMenuList() {
      //const menuList=this.axios.get("/menus");
      const menuList = [
        { name: "用户管理", childList: ["用户列表"], id: 0 },
        { name: "权限管理", childList: ["角色列表", "权限列表"], id: 1 },
        {
          name: "商品管理",
          childList: ["商品列表", "分类列表", "商品分类"],
          id: 2
        },
        {
          name: "订单管理",
          childList: ["订单管理"],
          id: 3
        },
        {
          name: "数据统计",
          childList: ["数据报表"],
          id: 4
        }
      ];
      this.menuList = menuList;
    },
    toggle() {
      this.isCollapse = !this.isCollapse;
    },
    saveNavstate(activeIndex) {
      window.sessionStorage.setItem("activeIndex", activeIndex);
      this.activeIndex=activeIndex;
    }
  }
};
</script>
<style scoped>
* {
  color: aliceblue;
}
.out {
  float: right;
}
.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
}
.el-aside {
  background-color: #333744;
}
.el-main {
  background-color: #eee;
}
.homeContainer {
  height: 100%;
}
.name {
  font-size: 25px;
}
.el-aside .el-menu {
  border-right: none;
}
.toggle-button {
  height: 25px;
  width: 100%;
  letter-spacing: 0.2rem;
  text-align: center;
  background-color:rgb(34, 178, 46);

}
</style>